local UIBase = require("view.UIBase")
local ChatContentCell = class("ChatContentCell", UIBase)
local Vector2 = require("utils.Vector2")
local Vector3 = require("utils.Vector3")

local CONTENT_NORMAL_HEIGHT = 60
local CELL_NORMAL_HEIGHT = 100

function ChatContentCell:ctor(parent, chatMsg)
    self._chatMsg = chatMsg
    local res = "ChatContentCell"
    if chatMsg:isRight() then
        res = "ChatRightContentCell"
    end
    local resource = {
        path = "Prefabs/View/Chat",
        name = res,
        parent = parent
    }
    ChatContentCell.super.ctor(self, resource)
end

function ChatContentCell:awake()
    self._rect = self._panel.rect
    self._textName.text = self._chatMsg:getName()
    self._textContent.text = self._chatMsg:getContent()
    local preferredWidth = self._textContent.preferredWidth
    local preferredHeight = self._textContent.preferredHeight
    local newContentHeight = preferredHeight + 10
    if newContentHeight > CONTENT_NORMAL_HEIGHT then
        local oldSize = self._imageContent.sizeDelta
        local offset = newContentHeight - CONTENT_NORMAL_HEIGHT
        self._imageContent.sizeDelta = Vector2.new(oldSize.x, newContentHeight)
        local oldRectSize = self._panel.sizeDelta
        self._panel.sizeDelta = Vector2.new(oldRectSize.x, CELL_NORMAL_HEIGHT + offset)
        printDebug("ChatCOnCell " .. offset)
        self._root.anchoredPosition = Vector2.new(0, offset)
    end
end

function ChatContentCell:start()
end

function ChatContentCell:getSize()
    return {width = self._rect.width, height = self._rect.height}
end

function ChatContentCell:getPanel()
    return self._panel
end

return ChatContentCell
